-
Notifications
You must be signed in to change notification settings - Fork 151
Stop using Tracer.Instance if we don't need to
#7744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stop using Tracer.Instance if we don't need to
#7744
Conversation
| CommandType = typeof(TCommand); | ||
|
|
||
| if (TryGetIntegrationDetails(CommandType.FullName, out var integrationId, out var dbTypeName)) | ||
| if (TryGetIntegrationDetails(Tracer.Instance.Settings.DisabledAdoNetCommandTypes, CommandType.FullName, out var integrationId, out var dbTypeName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is actually kind of annoying. As it's in a static cctor, we can't pass it in anywhere, which means there's one DbScopeFactoryTests test which will use this and end up initializing the global tracer. Oh well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:sorry: pretty sure this was me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. I understand that we want to minimize work but I feel like we should calculate all DbCommands regardless of config (i.e. no dependency here) and then we do the config check on the hot path, which allows this setting to be hot-reloadable or "config at runtime" ready
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concretely, I'm suggesting that we remove the TryGetIntegrationDetails call in the static constructor of Cache<TCommand> and refactor the other call in CreateDbCommandScope a bit. Perhaps in a separate PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see arguments both ways tbh.
The only downside to @zacharycmontoya's proposal would be more work to do for custom DbCommands (ones that we don't explicitly know about), which are also marked as disabled initially, and which customers have marked as disabled. The question I would have is whether that's ok - e.g. if they're disabled because we're erroring out literally running TryGetIntegrationDetails, and that's why they disabled it, then that could be a problem. If it's just an optimization, then yes, it probably is fine.
That said, this actually is technically already hot-reloadable. The DisabledAdoNetCommandTypes setting passed in here is used to decide whether to populate the cache for custom types, but if we don't populate the cache, then we run TryGetIntegrationDetails() and check DisabledAdoNetCommandTypes at runtime anyway. So if this changes, then the result changes, it will just never be cached in that scenario.
So on that basis, I think removing the TryGetIntegrationDetails has a small amount of risk (if customer disabled adonet due to errors - not sure if that's really possible, but I can believe it), means a small bit more work (calculating values which will never be used), and doesn't change how hot-reloadable we are in general (though if we made it hot reloadable, we'd have to rethink how caching works). The plus side is it removes the static access to Tracer.Instance which is better for tests.
So yeah, I'm torn 🤷♂️ I'd say separate PR either way, given the questions, as the current behaviour in this PR is identical to the existing. But it's worth thinking about
This comment has been minimized.
This comment has been minimized.
| CommandType = typeof(TCommand); | ||
|
|
||
| if (TryGetIntegrationDetails(CommandType.FullName, out var integrationId, out var dbTypeName)) | ||
| if (TryGetIntegrationDetails(Tracer.Instance.Settings.DisabledAdoNetCommandTypes, CommandType.FullName, out var integrationId, out var dbTypeName)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:sorry: pretty sure this was me
| [Fact] | ||
| public void CanRoundTripPathwayContext() | ||
| [Theory] | ||
| [CombinatorialData] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😃
Execution-Time Benchmarks Report ⏱️Execution-time results for samples comparing This PR (7744) and master. ✅ No regressions detected - check the details below Full Metrics ComparisonFakeDbCommand
HttpMessageHandler
Comparison explanationExecution-time benchmarks measure the whole time it takes to execute a program, and are intended to measure the one-off costs. Cases where the execution time results for the PR are worse than latest master results are highlighted in **red**. The following thresholds were used for comparing the execution times:
Note that these results are based on a single point-in-time result for each branch. For full results, see the dashboard. Graphs show the p99 interval based on the mean and StdDev of the test run, as well as the mean value of the run (shown as a diamond below the graph). Duration chartsFakeDbCommand (.NET Framework 4.8)gantt
title Execution time (ms) FakeDbCommand (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (74ms) : 69, 80
master - mean (75ms) : 69, 81
section Bailout
This PR (7744) - mean (80ms) : 74, 86
master - mean (80ms) : 75, 86
section CallTarget+Inlining+NGEN
This PR (7744) - mean (1,067ms) : 1016, 1118
master - mean (1,065ms) : 1013, 1117
FakeDbCommand (.NET Core 3.1)gantt
title Execution time (ms) FakeDbCommand (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (118ms) : 110, 125
master - mean (119ms) : 111, 127
section Bailout
This PR (7744) - mean (120ms) : 113, 127
master - mean (120ms) : 113, 127
section CallTarget+Inlining+NGEN
This PR (7744) - mean (762ms) : 729, 796
master - mean (765ms) : 733, 797
FakeDbCommand (.NET 6)gantt
title Execution time (ms) FakeDbCommand (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (106ms) : 99, 113
master - mean (106ms) : 101, 112
section Bailout
This PR (7744) - mean (106ms) : 99, 113
master - mean (105ms) : 100, 111
section CallTarget+Inlining+NGEN
This PR (7744) - mean (708ms) : 680, 735
master - mean (722ms) : 688, 755
FakeDbCommand (.NET 8)gantt
title Execution time (ms) FakeDbCommand (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (105ms) : 99, 111
master - mean (106ms) : 99, 112
section Bailout
This PR (7744) - mean (105ms) : 98, 112
master - mean (105ms) : 100, 110
section CallTarget+Inlining+NGEN
This PR (7744) - mean (689ms) : 662, 717
master - mean (696ms) : 666, 725
HttpMessageHandler (.NET Framework 4.8)gantt
title Execution time (ms) HttpMessageHandler (.NET Framework 4.8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (193ms) : 189, 197
master - mean (194ms) : 190, 198
section Bailout
This PR (7744) - mean (196ms) : 194, 199
master - mean (197ms) : 195, 199
section CallTarget+Inlining+NGEN
This PR (7744) - mean (1,116ms) : 1058, 1175
master - mean (1,122ms) : 1051, 1193
HttpMessageHandler (.NET Core 3.1)gantt
title Execution time (ms) HttpMessageHandler (.NET Core 3.1)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (277ms) : 273, 282
master - mean (277ms) : 273, 282
section Bailout
This PR (7744) - mean (280ms) : 273, 286
master - mean (277ms) : 273, 282
section CallTarget+Inlining+NGEN
This PR (7744) - mean (911ms) : 851, 971
master - mean (909ms) : 866, 952
HttpMessageHandler (.NET 6)gantt
title Execution time (ms) HttpMessageHandler (.NET 6)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (270ms) : 266, 274
master - mean (273ms) : 266, 279
section Bailout
This PR (7744) - mean (270ms) : 267, 274
master - mean (271ms) : 268, 274
section CallTarget+Inlining+NGEN
This PR (7744) - mean (880ms) : 845, 915
master - mean (884ms) : 841, 926
HttpMessageHandler (.NET 8)gantt
title Execution time (ms) HttpMessageHandler (.NET 8)
dateFormat x
axisFormat %Q
todayMarker off
section Baseline
This PR (7744) - mean (269ms) : 265, 274
master - mean (270ms) : 263, 277
section Bailout
This PR (7744) - mean (270ms) : 267, 273
master - mean (269ms) : 266, 273
section CallTarget+Inlining+NGEN
This PR (7744) - mean (823ms) : 805, 841
master - mean (829ms) : 808, 849
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
8a3aee6 to
753da8d
Compare
1b1f494 to
f94e51b
Compare
753da8d to
3a96423
Compare
f94e51b to
75937f5
Compare
3a96423 to
f01f8c6
Compare
75937f5 to
8111379
Compare
f01f8c6 to
4fd8303
Compare
8111379 to
177c2a0
Compare
10ce7a6 to
47ddbf9
Compare
2fbbd7f to
c677778
Compare
47ddbf9 to
62b1d54
Compare
c677778 to
1ad1119
Compare
62b1d54 to
854cac9
Compare
1ad1119 to
d33ef91
Compare
854cac9 to
7763c79
Compare
d33ef91 to
9d94c38
Compare
7763c79 to
71c8119
Compare
9d94c38 to
a34b7b5
Compare
71c8119 to
aad788e
Compare
a34b7b5 to
fe19d1a
Compare
aad788e to
bf267a8
Compare
fe19d1a to
b8b2b59
Compare
bf267a8 to
451e24d
Compare
b8b2b59 to
9ceef6e
Compare
451e24d to
dca9144
Compare
9ceef6e to
c043b52
Compare
efe95e4 to
0e2c7d3
Compare
447027a to
9db67e4
Compare
0e2c7d3 to
18206ad
Compare
Summary of changes
Updates a couple of places where we're calling
Tracer.Instancewhere we don't need toReason for change
In one of my other PRs I accidentally broke something that should only have affected integration tests, but a bunch of unit tests broke. It highlighted where they were using
Tracer.Instanceand setting the global tracer for tests. In other places, it revealed that code that tests that looked independent of other tests really wasn't...Calling
Tracer.Instancepotentially does a lot of work, as it initializes the tracer. It's also hard to follow if we're making static calls out in places we don't need to. So just pass through the settings we want instead.Implementation details
Instead of calling
Tracer.Instance.Settings, use the value ofTracerorTracerSettingsthat's already available wherever possible. It makes the tests cleaner too.Test coverage
Same coverage, just a bit cleaner
Other details
Included as part of the config stack, just because I already refactored some of this code, and can't be bothered to faff with merge conflicts:
https://datadoghq.atlassian.net/browse/LANGPLAT-819
MutableSettingsfromTracerSettings#7522MutableSettingson dynamic config changes #7525DefaultServiceNametoMutableSettings#7530PerTraceSettings.GetServiceName()#7532TracerSettingsto useMutableSettingswhere appropriate #7543IsIntegrationEnabled(),IsErrorStatusCode(), andGetIntegrationAnalyticsSampleRate()#7544DictionaryExtensions.SequenceEqual#7722SettingsManagerfor managing mutable settings and ExporterSettings #7695TracerSettingswhich can change at runtime #7723MutableSettingsandExporterSettingswithout rebuilding #7724Tracer.Instanceif we don't need to #7744 👈